﻿using Newtonsoft.Json;
using System;
using System.Globalization;

namespace MiniFox.Infrastructure
{
    /// <summary>
    /// redirect response for ajax request
    /// </summary>
    public class RedirectResponse : Response, IRedirectResponse
    {
        /// <summary>
        /// 
        /// </summary>
        public RedirectResponse() : this(CultureInfo.CurrentCulture)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cultureInfo"></param>
        public RedirectResponse(CultureInfo cultureInfo) : base(cultureInfo)
        {
        }

        private RedirectResponse(string redirectUri) : this(redirectUri, CultureInfo.CurrentCulture)
        {
        }
        private RedirectResponse(string redirectUri, CultureInfo cultureInfo) : this(cultureInfo)
        {
            this.RedirectUri = redirectUri;
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("redirectUri")]
        public string RedirectUri { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return RedirectUri;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static implicit operator string(RedirectResponse response)
        {
            return response.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static implicit operator Uri(RedirectResponse response)
        {
            return new Uri(response.ToString());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static implicit operator RedirectResponse(string uri)
        {
            return new RedirectResponse(uri);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static implicit operator RedirectResponse(Uri uri)
        {
            return new RedirectResponse(uri.ToString());
        }
    }


    /// <summary>
    /// 一般响应
    /// </summary>
    [JsonObject]
    public class RedirectResponse<T> : RedirectResponse where T : class
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public RedirectResponse(T data) : this(data, CultureInfo.CurrentCulture)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="cultureInfo"></param>
        public RedirectResponse(T data, CultureInfo cultureInfo) : base(cultureInfo)
        {
            Data = data;
        }
        /// <summary>
        /// 响应结果(业务模型或视图模型)
        /// </summary>
        [JsonProperty("data")]
        public T Data { get; set; }
    }
}
